package com.itheima.commons.autoconfig.template;

import cn.hutool.core.codec.Base64;
import com.baidu.aip.face.AipFace;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

public class AipFaceTemplate {

    @Autowired
    private AipFace client;

    /**
     * 检测图片中是否包含人脸
     *
     * @param imageBytes
     * @return
     */
    public Boolean detectFace(byte[] imageBytes) {
        // 人脸检测
        JSONObject res = client.detect(Base64.encode(imageBytes), "BASE64", null);
        return res.getString("error_msg").equalsIgnoreCase("SUCCESS");
    }

}
